class NetworkDialog : DialogFragment() {
    private var wifiChecker: WifiChecker? = null

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return MaterialAlertDialogBuilder(requireContext())
            .setTitle("网络连接")
            .setMessage(buildNetworkMessage())
            .setPositiveButton("打开WiFi设置") { _, _ ->
                openWifiSettings()
            }
            .setNegativeButton("取消", null)
            .create()
    }

    private fun buildNetworkMessage(): String {
        return when (wifiChecker?.checkWifiConnection()) {
            is WifiStatus.WifiDisabled -> "请开启WiFi以继续操作"
            is WifiStatus.NotConnected -> "请连接到与眼镜设备相同的WiFi网络"
            is WifiStatus.Connected -> {
                val ssid = (wifiChecker?.checkWifiConnection() as WifiStatus.Connected).ssid
                "当前连接到: $ssid\n请确保眼镜设备也连接到相同网络"
            }
            null -> "检查网络状态出错"
        }
    }

    private fun openWifiSettings() {
        startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
    }
} 